package org.dreamwork.jasmine2.restful;

import com.google.gson.annotations.Expose;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: seth.yang
 * Date: 14-11-17
 * Time: 下午4:20
 */
public class APIDefinition extends AbstractRestfulAPIDefinition {
    @Expose
    protected String className;
    @Expose
    protected Map<String, MethodDefinition> methods = new HashMap<String, MethodDefinition> ();
    protected Class type;
    protected List<Method> beforeApiExecuteMethods = new ArrayList<Method> ();

    public String getClassName () {
        return className;
    }

    void setClassName (String className) {
        this.className = className;
    }

    public Map<String, MethodDefinition> getMethods () {
        return methods;
    }

    void setMethods (Map<String, MethodDefinition> methods) {
        this.methods = methods;
    }

    void addMethod (MethodDefinition method) {
        methods.put (method.getPattern (), method);
    }

    public Class getType () {
        return type;
    }

    public void setType (Class type) {
        this.type = type;
    }

    public MethodDefinition getMethod (String pattern) {
        return methods.get (pattern);
    }

    public boolean isMethodSupported (String pattern, MethodType type) {
        if (!methods.containsKey (pattern))
            return false;

        MethodDefinition method = methods.get (pattern);
        return method.getType () == type;
    }
}